package cn.cycleif.app.controller;

import cn.cycleif.app.domain.dto.AnswerDTO;
import cn.cycleif.app.service.AnswerService;
import cn.cycleif.util.R;
import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Date: 25/2/10-13:52
 * @Desc:
 */
@RequestMapping("/api/answer")
@Tag(name = "回答接口", description = "提供对回答进行增删改查的接口")
@RestController
@SaIgnore
public class AnswerController {

  @Autowired
  private AnswerService answerService;

  @GetMapping("/list/{id}")
  @Operation(summary = "获取回答列表")
  public R<Object> getList(
      @PathVariable("id") Integer questId,
      @RequestParam("order") String order
  ) {
    return answerService.getList(questId, order);
  }

  @GetMapping("/user/{id}")
  @Operation(summary = "获取用户回答列表")
  public R<Object> getUserAnswerList(@PathVariable("id") Integer id) {
    return answerService.getUserAnswerList(id);
  }

  @PostMapping
  @Operation(summary = "新增回答")
  @SaCheckLogin
  public R<String> addAnswer(@RequestBody AnswerDTO dto) {
    return answerService.addAnswer(dto);
  }

  @PutMapping
  @Operation(summary = "修改回答")
  @SaCheckLogin
  public R<String> updateAnswer(@RequestBody AnswerDTO dto) {
    return answerService.updateAnswer(dto);
  }

  @DeleteMapping("/{id}")
  @Operation(summary = "删除回答")
  @SaCheckLogin
  public R<String> deleteAnswer(@PathVariable("id") Integer id) {
    return answerService.deleteAnswer(id);
  }
}
